package cn.easyar.samples.helloarqrcode;

import android.app.Application;
import android.content.Context;
import android.util.Log;


import com.orhanobut.logger.AndroidLogAdapter;

import java.util.ArrayList;

import io.agora.AgoraAPIOnlySignal;
import io.agora.rtc.IRtcEngineEventHandler;
import io.agora.rtc.RtcEngine;

public class MyApplication extends Application {
    public static Context applicationContext;
    private static MyApplication mInstance;
    public static MyApplication the() {
        return mInstance;
    }

    public MyApplication() {
        mInstance = this;
    }

    public static String[] contentListA = {"煤码头#1配电室、远端输煤配电室", "煤码头#2配电室",
            "综合码头", "联控楼各配电室"};
    public static String[] standardListA = {"燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准"};

    public static String[] contentListB = {"码头和煤码头排污泵房", "T-01转运站/ C-01A/B皮带沿线",
            "T-02转运站/ C-02A/B皮带沿线", "T03转运站/ C-03A/B皮带沿线",
            "采样机房", "T04转运站/ C-04A/B皮带沿线",
            "T21转运站/ C-21A/B皮带沿线", "T22转运站/C-22A/B皮带沿线",
            "T23转运站/C-23A皮带沿线", "T24转运站/C-24皮带沿线/C-23B皮带沿线",
            "T05转运站/ C-12皮带沿线/ C-25A/B皮带沿线/ C-11A皮带沿线", "T11转运站/ C-11B皮带沿线",
            "#含煤废处理站及外围", "脱水楼（不包括变频器控制箱、配电室、直流和UPS系统）",
            "#1脱硫区域（不包括变频器控制箱、配电室、直流和UPS系统）",
            "#2脱硫区域（不包括变频器控制箱、配电室、直流和UPS系统）"};

    public static String[] standardListB = {"燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准"};

    public static String[] contentListC = {"采样楼", "T-06转运站",
            "煤仓层", "C-15A、C-15B、C-28A、C-28B、 C-33皮带沿线区域",
            "碎煤机楼0米外围", "碎煤机楼",
            "C-13A、C-13B、C-27A、C-27B沿线区域", "磨制楼及磨制皮带沿线区域",
            "#1含煤废水处理站及外围", "#3脱硫区域（不包括变频器控制箱、配电室、直流和UPS系统）",
            "#4脱硫区域（不包括变频、配电室、直流和UPS系统）"};
    public static String[] standardListC = {"燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准",
            "燃脱部电气维护规程新改标准"};

    private String[] contentChildList = {"电机是否正常", "照明开关是否正常", "检修箱是否正常", "变频器是否正常"};
    private String[] standardChildList = {"燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准", "燃脱部电气维护规程新改标准"};



    public static int aid = 0;
    private AgoraAPIOnlySignal m_agoraAPI;
    private RtcEngine mRtcEngine;


    @Override
    public void onCreate() {
        super.onCreate();

        applicationContext = this.getApplicationContext();
        //日志

        setupAgoraEngine();
        com.orhanobut.logger.Logger.addLogAdapter(new AndroidLogAdapter());
    }



    public RtcEngine getmRtcEngine() {
        return mRtcEngine;
    }

    public AgoraAPIOnlySignal getmAgoraAPI() {
        return m_agoraAPI;
    }


    private OnAgoraEngineInterface onAgoraEngineInterface;

    //声网信令
    private final IRtcEngineEventHandler mRtcEventHandler = new IRtcEngineEventHandler() {
        @Override
        public void onFirstRemoteVideoDecoded(final int uid, int width, int height, int elapsed) {
            if (onAgoraEngineInterface != null) {
                onAgoraEngineInterface.onFirstRemoteVideoDecoded(uid, width, height, elapsed);
            }
        }

        @Override
        public void onUserOffline(int uid, int reason) {
            if (onAgoraEngineInterface != null) {
                onAgoraEngineInterface.onUserOffline(uid, reason);
            }
        }

        @Override
        public void onUserMuteVideo(final int uid, final boolean muted) {
            if (onAgoraEngineInterface != null) {
                onAgoraEngineInterface.onUserMuteVideo(uid, muted);
            }
        }

        @Override
        public void onJoinChannelSuccess(String channel, int uid, int elapsed) {
            super.onJoinChannelSuccess(channel, uid, elapsed);
            if (onAgoraEngineInterface != null) {
                onAgoraEngineInterface.onJoinChannelSuccess(channel, uid, elapsed);
            }
        }

    };
    private void setupAgoraEngine() {
        String appID = getString(R.string.agora_app_id);

        try {
            m_agoraAPI = AgoraAPIOnlySignal.getInstance(this, appID);
            mRtcEngine = RtcEngine.create(getBaseContext(), appID, mRtcEventHandler);
        } catch (Exception e) {
            throw new RuntimeException("NEED TO check rtc sdk init fatal error\n" + Log.getStackTraceString(e));
        }
    }

    public interface OnAgoraEngineInterface {
        void onFirstRemoteVideoDecoded(final int uid, int width, int height, int elapsed);

        void onUserOffline(int uid, int reason);

        void onUserMuteVideo(final int uid, final boolean muted);

        void onJoinChannelSuccess(String channel, int uid, int elapsed);
    }
}
